package com.group.order.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group.commons.entity.DoctorDto;
import com.group.order.entity.OrderList;
import com.group.order.entity.Registration;
import com.group.order.entity.vo.RegistrationDetailVo;
import com.group.order.entity.vo.RegistrationListVo;
import com.group.order.mapper.RegistrationMapper;
import com.group.order.service.OrderService;
import com.group.order.service.RegistrationService;
import com.group.order.trans.RegistrationTrans;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
@Slf4j
public class RegistrationServiceImpl extends ServiceImpl<RegistrationMapper, Registration> implements RegistrationService {
    @Resource
    RegistrationMapper registrationMapper;

    @Resource
    OrderService orderService;


    public List<RegistrationListVo> getPage(Page<RegistrationListVo> page) {
        List<RegistrationListVo> list = registrationMapper.selectPageVo(page);
        return list;
    }

    // TODO: 2022/6/7 调用医生微服务查询医生信息 
    @Override
    public RegistrationDetailVo getRegistrationDetail(int id) {
        Registration registration = registrationMapper.selectById(id);
        HashMap<String,Object> map = new HashMap<>();
        map.put("number",registration.getNumber());
        List<OrderList> list = orderService.listByMap(map);
        log.info("order = {}",list);
        OrderList orderList = list.get(0);
        DoctorDto doctorDto = new DoctorDto();
        doctorDto.setName("张三");
        doctorDto.setDepartment("妇产科");
        doctorDto.setHospital("华西医院");
        doctorDto.setPost("一级专家");
        RegistrationDetailVo registrationDetailVo = RegistrationTrans.MAPPER.convertDetailVo(doctorDto, registration, orderList);
        log.info("封装对象是 {}",registrationDetailVo);
        return null;
    }
}

